package com.tan.lbs.service.impl;

import com.tan.lbs.dao.DialogNodeDAO;
import com.tan.lbs.dao.DialogNodeOrderDAO;
import com.tan.lbs.dao.GameDAO;
import com.tan.lbs.dao.ItemDAO;
import com.tan.lbs.dao.MediaDAO;
import com.tan.lbs.dao.NPCDAO;
import com.tan.lbs.dao.QuestDAO;
import com.tan.lbs.dao.impl.DialogNodeDAOImpl;
import com.tan.lbs.dao.impl.DialogNodeOrderDAOImpl;
import com.tan.lbs.dao.impl.GameDAOImpl;
import com.tan.lbs.dao.impl.ItemDAOImpl;
import com.tan.lbs.dao.impl.MediaDAOImpl;
import com.tan.lbs.dao.impl.NPCDAOImpl;
import com.tan.lbs.dao.impl.QuestDAOImpl;
import com.tan.lbs.entity.DialogNodeOrder;
import com.tan.lbs.entity.Game;
import com.tan.lbs.entity.Item;
import com.tan.lbs.entity.Media;
import com.tan.lbs.entity.NPC;
import com.tan.lbs.service.MediaService;

public class MediaServiceImpl implements MediaService {
	
	private MediaDAO mediaDAO;
	private GameDAO gameDAO;
	private ItemDAO itemDAO;
	private NPCDAO npcDAO;
	private QuestDAO questDAO;
	private DialogNodeDAO dialogNodeDAO;
	
	public MediaServiceImpl() {
		mediaDAO = new MediaDAOImpl();
		gameDAO = new GameDAOImpl();
		itemDAO = new ItemDAOImpl();
		npcDAO = new NPCDAOImpl();
		questDAO = new QuestDAOImpl();
		dialogNodeDAO = new DialogNodeDAOImpl();
	}

	@Override
	public String previewUploadImages(String requestUpload,
			String gameObjID) {
		String pictureID = "";
		if(requestUpload.equalsIgnoreCase("gameicon")) {
			pictureID = gameDAO.readByID(gameObjID).getIconID();
		} else if(requestUpload.equalsIgnoreCase("gamecover")) {
			pictureID = gameDAO.readByID(gameObjID).getGameCoverID();
		} else if(requestUpload.equalsIgnoreCase("itemicon")) {
			pictureID = itemDAO.readByID(gameObjID).getIconID();
		} else if(requestUpload.equalsIgnoreCase("itemcontainedmedia")) {
			pictureID = itemDAO.readByID(gameObjID).getContainedMediaID();
		} else if(requestUpload.equalsIgnoreCase("npcIcon")) {
			pictureID = npcDAO.readByID(gameObjID).getIconID();
		} else if(requestUpload.equalsIgnoreCase("npcFigure")) {
			pictureID = npcDAO.readByID(gameObjID).getFigureID();
		} else if(requestUpload.equalsIgnoreCase("dNodeContainedMedia")) {
			pictureID = dialogNodeDAO.readByID(gameObjID).getContainedMediaID();
		} else if(requestUpload.equalsIgnoreCase("questIcon")) {
			pictureID = questDAO.readByID(gameObjID).getIconID();
		}
		if(pictureID == null ||pictureID.isEmpty()) return null;
		Media m = mediaDAO.readByID(pictureID);
		return m.getPath() + m.getMediaID()+"." + m.getType();
	}

}
